
public class MultiThreadTest implements Runnable
{
	public static Object mutex = new  Object();
	int id =  0;
	
	MultiThreadTest(int id)
	{
		this.id = id;
	}
	
	public static void main(String[] args)
	{
		Thread t1 = new Thread(new MultiThreadTest(0));
		Thread t2 = new Thread(new MultiThreadTest(1));
		t1.start(); t2.start();
	}

	@Override
	public void run()
	{
		switch (id)
		{
			case 1:
				while(true)
				{
					System.out.println("While loop 1");
					synchronized (mutex)
					{
						try
						{
							System.out.println("Waiting");
							mutex.wait();
							System.out.println("Can go on =)");
						} catch (InterruptedException e)
						{
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}
				

			default:
				while(true)
				{
					System.out.println("While loop 0");
					synchronized (mutex)
					{
						System.out.println("in mutex");
						mutex.notify();
						System.out.println("Notified:");
					}
				}
		}
		
	}
}
